﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DonutLandLibrary.Data
{
    class RobotsData
    {
        //public static void SaveRobot(Robots.Robot robotsRobot)
        //{
        //    RobotsEntities entities = new RobotsEntities();

        //    //create the LINQ DB entity
        //    Robot robot = new Robot();

        //    //add the property values
        //    robot.ID = robotsRobot.ID;
        //    robot.CurrentEnvironment = robotsRobot.CurrentEnvironment.ID;
        //    robot.CurrentSquare = robotsRobot.CurrentSquare.ID;
        //    robot.EnergyDepletionReserve = robotsRobot.EnergyDepletionReserve;
        //    robot.EnergyLevel = robotsRobot.EnergyLevel;
        //    robot.ProtectiveCasing = robotsRobot.ProtectiveCasing;
        //    robot.ProtectiveCasingReserve = robotsRobot.ProtectiveCasingReserve;
        //    robot.RobotAlive = robotsRobot.RobotAlive;
        //    robot.GeneticProfile = robotsRobot.GeneticProfile.ID;

        //    entities.SaveChanges();
        //}


        public static int Save(Robots.Robot robotsRobot)
        {
            RobotsEntities entities = new RobotsEntities();

            //create the LINQ DB entity
            Robot robot = new Robot();

            //add the property values
            //robot.ID = robotsRobot.ID;
            robot.CurrentEnvironment = robotsRobot.CurrentEnvironment.ID;
            robot.CurrentSquare = robotsRobot.CurrentSquare.ID;
            robot.EnergyDepletionReserve = robotsRobot.EnergyDepletionReserve;
            robot.EnergyLevel = robotsRobot.EnergyLevel;
            robot.ProtectiveCasing = robotsRobot.ProtectiveCasing;
            robot.ProtectiveCasingReserve = robotsRobot.ProtectiveCasingReserve;
            robot.RobotAlive = robotsRobot.RobotAlive;
            robot.GeneticProfile = robotsRobot.GeneticProfile.ID;
            robot.RobotDirection = (int)robotsRobot.RobotDirection;
            robot.CycleAdded = robotsRobot.CycleAdded;
            
            entities.AddToRobots(robot);

            entities.SaveChanges();

            return robot.ID;
        }

        public static void Update(Robots.Robot robotsRobot)
        {
            RobotsEntities entities = new RobotsEntities();

            //getthe LINQ DB entity
            Robot robot = entities.Robots.Where(rb => rb.ID == robotsRobot.ID).FirstOrDefault();

            //add the property values
            //robot.ID = robotsRobot.ID;
            robot.CurrentEnvironment = robotsRobot.CurrentEnvironment.ID;
            robot.CurrentSquare = robotsRobot.CurrentSquare.ID;
            robot.EnergyDepletionReserve = robotsRobot.EnergyDepletionReserve;
            robot.EnergyLevel = robotsRobot.EnergyLevel;
            robot.ProtectiveCasing = robotsRobot.ProtectiveCasing;
            robot.ProtectiveCasingReserve = robotsRobot.ProtectiveCasingReserve;
            robot.RobotAlive = robotsRobot.RobotAlive;
            robot.GeneticProfile = robotsRobot.GeneticProfile.ID;
            robot.RobotDirection = (int)robotsRobot.RobotDirection;
            robot.CycleAdded = robotsRobot.CycleAdded;

            //entities.AddToRobots(robot);

            entities.SaveChanges();

            //return robot.ID;
        }

    }
}
